/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
package org.swan.plugin.beetl;
public class CodeFunction {
    public String firstLower(String str) {
        if (str == null || str.isEmpty())
            return str;
        return Character.toLowerCase(str.charAt(0)) + str.substring(1);
    }

    public String firstUpper(String str) {
        if (str == null || str.isEmpty())
            return str;
        return Character.toUpperCase(str.charAt(0)) + str.substring(1);
    }

    public String snakeToCamel(String str) {
        if (str == null)
            return str;
        StringBuilder sb = new StringBuilder();
        boolean upper = false;
        for (char c : str.toCharArray()) {
            if (c == '_') {
                upper = true;
            } else {
                sb.append(upper ? Character.toUpperCase(c) : c);
                upper = false;
            }
        }
        return sb.toString();
    }
    public String camelToSnake(String str) {
        if (str == null)
            return str;
        StringBuilder sb = new StringBuilder();
        for (char c : str.toCharArray()) {
            if (Character.isUpperCase(c)) {
                sb.append('_').append(Character.toLowerCase(c));
            } else {
                sb.append(c);
            }
        }
        return sb.toString();
    }
    public String getter(String str, boolean isBoolean) {
        if (isBoolean)
            return snakeToCamel("is" + firstUpper(str));
        return snakeToCamel("get" + firstUpper(str));
    }

    public String setter(String str) {
        return snakeToCamel("set" + firstUpper(str));
    }
}
